package com.shensi.adminCollect.controller.station;

import com.shensi.common.core.domain.ResultData;
import com.shensi.adminCollect.common.enums.ErrorCode;
import com.shensi.adminCollect.common.exception.CustomException;
import com.shensi.adminCollect.common.utils.EnumsContainer;
import com.shensi.adminCollect.domain.station.vo.ReceiptContentVO;
import com.shensi.adminCollect.enums.station.ReceiptType;
import com.shensi.adminCollect.service.station.IReceiptSectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.shensi.common.core.domain.model.LoginUser;
import com.shensi.common.core.utils.SecurityUtils;
import com.shensi.common.core.domain.entity.SysUser;
/**
 * @date 2024/1/23
 */
@RestController
@RequestMapping("receiptSection")
@Api(tags = "小票打印设置")
public class ReceiptSectionController {

    @Autowired
    private IReceiptSectionService receiptSectionService;

    @GetMapping("query")
    @ApiOperation("查询")
    public ResultData<ReceiptContentVO> queryList(@RequestParam("receiptType") Integer receiptTypeCode){
        ReceiptType receiptType = EnumsContainer.getEnumByKey(ReceiptType.class, receiptTypeCode);
        if (receiptType == null) {
            throw new CustomException(ErrorCode.VALIDATE_ERROR);
        }
        return ResultData.success(receiptSectionService.queryListWithDefault(SecurityUtils.getLoginSysUser().getEnterpriseId(),receiptType));
    }

    @GetMapping("queryDef")
    @ApiOperation("查询默认")
    public ResultData<ReceiptContentVO> queryDefList(@RequestParam("receiptType") Integer receiptTypeCode){
        ReceiptType receiptType = EnumsContainer.getEnumByKey(ReceiptType.class, receiptTypeCode);
        if (receiptType == null) {
            throw new CustomException(ErrorCode.VALIDATE_ERROR);
        }
        return ResultData.success(receiptSectionService.queryDefaultList(SecurityUtils.getLoginSysUser().getEnterpriseId(),receiptType));
    }

    @PostMapping("save")
    @ApiOperation("保存")
    public ResultData save(@RequestBody ReceiptContentVO contentVO){
        receiptSectionService.save(contentVO);
        return ResultData.success();
    }

}
